package net.comm.tags;



import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;





public class ArrayTag extends TagSupport {



	/**

	 * 

	 */

	private static final long serialVersionUID = 6048001007102991492L;

	private String name="";

	private String id="";

	private String css="";

	private String[][] options=null; //要下拉的变量数组

	private String value="";

	private String tagname="";

	private boolean optional=true;

	private boolean disabled=false;

	private String onkeypress="";

	private String onkeydown="";

	private String onchange="";

	public int doStartTag() {

	    try {
	    	
	    	
	        // Acquire the select tag we are associated with

	      boolean bselected=false;

	      JspWriter out = pageContext.getOut();

	      StringBuffer str = new StringBuffer("");

	      str.append("<select name='");

	      str.append(name);

	      str.append("'");
	      if (!id.trim().equals("")) 

	      {
	    	  str.append(" id=\"");

	    	  str.append(id);

	    	  str.append("\"");

	      }
	      if (!css.trim().equals("")) 

	      {
	    	  str.append(" class=\"");

	    	  str.append(css);

	    	  str.append("\"");

	      }
	      if (!onkeypress.trim().equals("")) 

	      {

	    	  str.append(" onkeypress=\"");

	    	  str.append(onkeypress);

	    	  str.append("\"");

	      }

	      if (!onkeydown.trim().equals("")) 

	      {

	    	  str.append(" onkeydown=\"");

	    	  str.append(onkeydown);

	    	  str.append("\"");

	      }

	      if (!onchange.trim().equals("")) 

	      {

	    	  str.append(" onChange=\"");

	    	  str.append(onchange);

	    	  str.append("\"");

	      }

	      if (disabled) str.append(" disabled ");

	      str.append(">");

	      if (optional)

	        str.append("<option value=''>" +
	        		tagname +
	        		"</option>");

	      if (options != null) {

	        for (int i = 0; i < options[0].length; i++) {

	          str.append("<option value='");

	          str.append(options[0][i]);

	          str.append("'");

	          if ((value!=null)&&(options[0][i].equals(value.trim()))) 

	          {

	             str.append(" selected ");

	             bselected=true;

	          }

	          str.append(">");

	          str.append(options[1][i]);

	          str.append("</option>");

	        }

	      }

	      //如果未选中的话

	      if (!bselected && value!=null && value.trim().length()>0)

	      {

	          str.append("<option value='"+value+"' selected>"+value+"</option>");

	      }

	      str.append("</select>");

	      out.print(str.toString());

	      //数据库操作执行完毕,释放连接

	    }

	    catch (Exception e) {

	    	e.printStackTrace();

	    }

	    return (SKIP_BODY);

	}

	public void setName(String name){

	    this.name = name;

	}

	public void setValue(String value){

	    this.value = value;

	}

	public String getValue(){

	    return value;

	}

	public void setoptional(boolean optional1)

	{

	    this.optional=optional1;

	}

	public void setDisabled(boolean disabled){

        this.disabled = disabled;

	}

	public void setOptions(String[][] options){

	    this.options = options;

	}

	public void setonkeypress(String onkeypress1)

	{

	    onkeypress=onkeypress1;

	}

	public void setonkeydown(String onkeydown1)

	{

	    onkeydown=onkeydown1;

	}

	public void setonchange(String onchange1)

	{

	    onchange=onchange1;

	}

	public String getTagname() {
		return tagname;
	}

	public void setTagname(String tagname) {
		this.tagname = tagname;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getCss() {
		return css;
	}

	public void setCss(String css) {
		this.css = css;
	}

}



